package com.ac.app.run3;

import java.io.File;

import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.jdbc.core.JdbcTemplate;

/**
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Copyright: Copyright AgileCentury 2004</p>
 * <p>Company: AgileCentury </p>
 * @author <a href="mailto:ac@agilecentury.com">Agile</a>
 * @version 1.0
 */

public class ClientDelApp {
	private final static String SEL_BS_SQL="select SHOT_PATH from PICK_BASE";
	private final static String CNT_PR_SQL="select count(*) from PICK_RECORD where SHOT=?";
    private static ClassPathXmlApplicationContext ctx;
 
    public ClientDelApp() {
    }

    public static void main(String[] args) {
        ctx = new ClassPathXmlApplicationContext(new String[] { "spring.xml"});
        JdbcTemplate jt = (JdbcTemplate) ctx.getBean("jdbcTemplate");
        String shotPath = (String)jt.queryForObject(SEL_BS_SQL, String.class);
        String optTime  = "20110417";
        try {
            File file = new File(shotPath);
            File[] dirFiles = file.listFiles();
            for (int i = 0; i < dirFiles.length; i++) {
                if (dirFiles[i].isDirectory()) {
                    if (optTime.compareTo(dirFiles[i].getName()) > 0) {
                        File[] files = dirFiles[i].listFiles();
                        for (int j = 0; j < files.length; j++) {
                        	int iCnt = jt.queryForInt(CNT_PR_SQL, new String[]{ files[j].getName()});
                        	if(iCnt==0){
                        		//System.out.println(files[j].getName());
                        		files[j].delete();
                        	}
                        }
                    }
                }
            }            
        } catch (Exception e) {
            e.printStackTrace();
        }
   }
}